//
//  LAB_StickersView.m
//  Camera
//
//  Created by Bodi on 16/8/17.
//  Copyright © 2016年 葛海一. All rights reserved.
//

#import "LAB_StickersView.h"
#import "LAB_Stickers_CollectionViewCell.h"
#import "LAB_GestureImageView.h"
@implementation LAB_StickersView

- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        self.stickers = @[@"1.png",@"2.png",@"3.png",@"4.png",@"5.png"];
        [self addSubview:self.stickersCollectionView];
    }
    return self;
}
#pragma mark - 贴纸菜单
- (UICollectionView *)stickersCollectionView{
    if (!_stickersCollectionView) {
        UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc]init];
        flowLayout.itemSize = CGSizeMake(85, 85);
        flowLayout.sectionInset = UIEdgeInsetsMake(0, 7.5, 0, 7.5);
        flowLayout.minimumLineSpacing = 5.0;
        flowLayout.minimumInteritemSpacing = 2.0;
        flowLayout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
        
        _stickersCollectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, WIDTH, 120) collectionViewLayout:flowLayout];
        _stickersCollectionView.backgroundColor = [UIColor blackColor];
        _stickersCollectionView.showsVerticalScrollIndicator = NO;
        _stickersCollectionView.showsHorizontalScrollIndicator = NO;
        _stickersCollectionView.delegate = self;
        _stickersCollectionView.dataSource = self;
        [_stickersCollectionView registerClass:[LAB_Stickers_CollectionViewCell class] forCellWithReuseIdentifier:@"LABStickersCollectionViewCell"];
        
        
    }
    return _stickersCollectionView;

}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{

    return self.stickers.count;

}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    LAB_Stickers_CollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"LABStickersCollectionViewCell" forIndexPath:indexPath];
    cell.array = self.stickers;
    cell.bodiView.image =  [UIImage imageNamed:self.stickers[indexPath.row]] ;
    return cell;


}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
//    UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(20, -200, 50, 50)];
//UIImage *image = [UIImage imageNamed:self.stickers[indexPath.row]] ;
//    imageView.image = image;
//    [self addSubview:imageView];
//    LAB_GestureImageView *gesture = [[LAB_GestureImageView alloc]initWithImage:[UIImage imageNamed:self.stickers[indexPath.row]] withFrame:CGRectMake(100, -300, 50, 50)];
//    [self addSubview:gesture];
    [[NSNotificationCenter defaultCenter] postNotificationName:@"trigger" object:self.stickers[indexPath.row] userInfo:nil];
    


}














@end
